<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="ajax.jsp"%>
<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <meta charset="UTF-8">
    <title>欢迎使用后台管理系统</title>
    <style>
        /* 重置样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        /* 页面主体 */
        body {
            font-family: sans-serif;
            background-color: #f5f5f5;
        }

        /* 表单 */
        .form {
            width: 100%;
            max-width: 600px;
            margin: 20px auto;
            padding: 20px;
        }

        .form-item {
            margin-bottom: 15px;
        }

        .form-label {
            display: block;
            margin-bottom: 5px;
        }

        .form-input {
            width: 100%;
            padding: 5px;
            border: 1px solid #ccc;
        }

        .textarea {
            width: 100%;
            height: 120px;
            padding: 5px;
            border: 1px solid #ccc;
        }

        .btn {
            display: inline-block;
            padding: 5px 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            text-decoration: none;
            color: #333;
            background-color: #f5f5f5;
            cursor: pointer;
        }

        .btn:hover {
            background-color: #e5e5e5;
        }

    </style>
</head>
<body>
<script>
    function updateComplain(url){
        let complainId = document.getElementById('complainId').value;
        let reps = document.getElementById('reps').value;
        if (reps === ''){
            alert("回复不能为空");
            return;
        }
        let complain = {
            complainId: complainId,
            reps: reps
        }
        axiosInstance.post(
            url,
            complain,
            {
                headers: headersJson
            }
        ).then((res)=>{
            console.log(res.data);
            if (res.data.code == 200){
                console.log("回复成功");
                document.getElementById('btn-msg').innerHTML = "回复成功";
                setTimeout(()=>{
                    document.getElementById('btn-msg').innerHTML = "";
                    navigateTo('/complain/getAllComplains');
                }, 1000);
            }else {
                console.log("回复失败");
                document.getElementById('btn-msg').innerHTML = "回复失败";
                setTimeout(()=>{
                    document.getElementById('btn-msg').innerHTML = "";
                }, 2000);
            }
        }).catch(e=>{
            console.log(e);
            console.log("回复出现异常");
            document.getElementById('btn-msg').innerHTML = "回复出现异常";
            setTimeout(()=>{
                document.getElementById('btn-msg').innerHTML = "";
            }, 2000);
        })
    }
</script>
<div class="main">
    <h2 style="text-align: center">回复意见反馈信息</h2>
    <form id="addForm" class="form" name="myform">
        <div class="form-item">
            <label for="contents">内容</label>
            <div class="form-input">
                ${complain.contents}
                <input type="hidden" name="contents" id="contents" value="${complain.contents}"/>
            </div>
        </div>
        <div class="form-item">
            <label for="reps">管理员回复</label>
            <div class="form-input">
                <textarea name="reps" id="reps" style="height: 120px"> </textarea>
            </div>
        </div>
        <div class="form-item">
            <input type="hidden" name="complainId" id="complainId" value="${complain.complainId}">
            <input type="hidden" name="userId" id="userId" value="${complain.userId}">
            <input type="hidden" name="title" id="title" value="${complain.title}">
            <input type="hidden" name="createTime" id="createTime" value="${complain.createTime}">
            <input type="hidden" name="status" id="status" value="${complain.status}">
            <button type="button" class="btn" onclick="updateComplain('/complain/updateComplain')" id="sub">立即提交</button>
            <button type="reset" class="btn" id="res">取消重置</button>
        </div>
        <div id="btn-msg"></div>
    </form>
</div>
</body>
</html>
